<script setup lang="ts">
import { ref } from 'vue'
import { calculateKellyRatio, calculateExpectedReturn, calculateOptimalParams } from './kellyUtils'

// 参数接口
interface SimulationParams {
  initialCapital: number
  initialPositionRatio: number // 初始头寸比例（百分比）
  coinFlipTimes: number
  threadCount: number
  winProb: number
  winOdds: number
  maxPyramidLevels: number // 金字塔最大层数
  betIncreaseRatio: number // 下注增长比例
  betDecreaseRatio: number // 下注降低比例
}

interface RecommendedParams {
  pyramidLevels: number
  strategy: 'conservative' | 'moderate' | 'aggressive' | 'optimal' | 'martingale' | 'anti-martingale'
  initialPosition?: number
  increaseRatio?: number
  decreaseRatio?: number
}

// 参数
const initialCapital = ref(100)
const initialPositionRatio = ref(0.02) // 初始头寸比例，默认2%
const coinFlipTimes = ref(1000)
const threadCount = ref(100)
const winProb = ref(0.35)
const winOdds = ref(3)
const maxPyramidLevels = ref(5) // 金字塔最大层数，默认5层
const betIncreaseRatio = ref(1.5) // 下注增长比例，默认1.5倍
const betDecreaseRatio = ref(0.7) // 下注降低比例，默认降低到70%

const running = ref(false)
const result = ref('')
const suggestion = ref('')
const showQuickApply = ref(false)
const recommendedParams = ref<RecommendedParams | null>(null)
const showMartingaleApply = ref(false)
const showAntiMartingaleApply = ref(false)
const martingaleOptimalParams = ref<{
  initialPosition: number
  increaseRatio: number
  decreaseRatio: number
  pyramidLevels: number
} | null>(null)
const antiMartingaleOptimalParams = ref<{
  initialPosition: number
  increaseRatio: number
  decreaseRatio: number
  pyramidLevels: number
} | null>(null)

function simulateMartingale(params: SimulationParams) {
  let capital = params.initialCapital
  let bet = capital * params.initialPositionRatio // 初始下注为资金的指定比例
  let bust = false
  let pyramidLevel = 0 // 当前金字塔层数

  for (let i = 0; i < params.coinFlipTimes; i++) {
    if (capital <= 0) {
      bust = true
      capital = 0
      break
    }
    // 确保下注不超过当前资金
    const actualBet = Math.min(bet, capital)
    const win = Math.random() < params.winProb
    if (win) {
      capital += actualBet * params.winOdds
      // 成功时，如果金字塔层数不为0且有调整空间，则减少下注
      if (params.maxPyramidLevels > 0 && pyramidLevel < params.maxPyramidLevels) {
        bet = bet * params.betDecreaseRatio
        pyramidLevel++
      }
    } else {
      capital -= actualBet
      // 失败时，如果金字塔层数不为0且有调整空间，则增加下注
      if (params.maxPyramidLevels > 0 && pyramidLevel < params.maxPyramidLevels) {
        bet *= params.betIncreaseRatio
        pyramidLevel++
      }
    }
  }
  return { capital, bust }
}

function simulateAntiMartingale(params: SimulationParams) {
  let capital = params.initialCapital
  let bet = capital * params.initialPositionRatio // 初始下注为资金的指定比例
  let bust = false
  let pyramidLevel = 0 // 当前金字塔层数

  for (let i = 0; i < params.coinFlipTimes; i++) {
    if (capital <= 0) {
      bust = true
      capital = 0
      break
    }
    // 确保下注不超过当前资金
    const actualBet = Math.min(bet, capital)
    const win = Math.random() < params.winProb
    if (win) {
      capital += actualBet * params.winOdds
      // 成功时，如果金字塔层数不为0且有调整空间，则增加下注
      if (params.maxPyramidLevels > 0 && pyramidLevel < params.maxPyramidLevels) {
        bet *= params.betIncreaseRatio
        pyramidLevel++
      }
    } else {
      capital -= actualBet
      // 失败时，如果金字塔层数不为0且有调整空间，则减少下注
      if (params.maxPyramidLevels > 0 && pyramidLevel < params.maxPyramidLevels) {
        bet = bet * params.betDecreaseRatio
        pyramidLevel++
      }
    }
  }
  return { capital, bust }
}

// 计算马丁格尔策略的最优参数
function calculateMartingaleOptimalParams(winProb: number, winOdds: number) {
  const kellyRatio = calculateKellyRatio(winProb, winOdds)
  const expectedReturn = calculateExpectedReturn(winProb, winOdds)

  // 马丁格尔策略专用参数计算
  let initialPosition: number
  let increaseRatio: number
  let decreaseRatio: number
  let pyramidLevels: number

  if (expectedReturn <= 0 || kellyRatio <= 0) {
    // 负期望收益，不建议使用马丁格尔
    initialPosition = 0.005 // 0.5%
    increaseRatio = 1.1
    decreaseRatio = 0.95
    pyramidLevels = 3
  } else {
    // 马丁格尔策略需要更保守的参数
    const safeKellyRatio = kellyRatio * 0.15 // 使用更保守的15%凯利比例
    initialPosition = Math.min(Math.max(safeKellyRatio, 0.003), 0.05) // 限制在0.3%-5%之间

    // 根据胜率调整参数
    if (winProb < 0.3) {
      // 低胜率，需要更激进的马丁格尔
      increaseRatio = Math.min(2.5, 1.8 + (0.5 - winProb) * 2)
      decreaseRatio = Math.max(0.3, 0.7 - (0.5 - winProb))
      pyramidLevels = Math.min(6, Math.max(3, Math.floor((0.5 - winProb) * 10)))
    } else if (winProb < 0.45) {
      // 中低胜率
      increaseRatio = 1.5 + (0.45 - winProb) * 2
      decreaseRatio = 0.7 - (0.45 - winProb) * 0.5
      pyramidLevels = 4
    } else {
      // 相对较高胜率，温和马丁格尔
      increaseRatio = 1.2 + kellyRatio
      decreaseRatio = 0.8
      pyramidLevels = 5
    }
  }

  return {
    initialPosition: Math.round(initialPosition * 10000) / 10000,
    increaseRatio: Math.round(increaseRatio * 100) / 100,
    decreaseRatio: Math.round(decreaseRatio * 100) / 100,
    pyramidLevels: pyramidLevels,
  }
}

// 计算反马丁格尔策略的最优参数
function calculateAntiMartingaleOptimalParams(winProb: number, winOdds: number) {
  const kellyRatio = calculateKellyRatio(winProb, winOdds)
  const expectedReturn = calculateExpectedReturn(winProb, winOdds)

  // 反马丁格尔策略专用参数计算
  let initialPosition: number
  let increaseRatio: number
  let decreaseRatio: number
  let pyramidLevels: number

  if (expectedReturn <= 0 || kellyRatio <= 0) {
    // 负期望收益，不建议使用反马丁格尔
    initialPosition = 0.01 // 1%
    increaseRatio = 1.1
    decreaseRatio = 0.9
    pyramidLevels = 2
  } else {
    // 反马丁格尔策略可以相对激进
    const safeKellyRatio = kellyRatio * 0.35 // 使用35%的凯利比例
    initialPosition = Math.min(Math.max(safeKellyRatio, 0.005), 0.15) // 限制在0.5%-15%之间

    // 根据胜率调整参数
    if (winProb > 0.6) {
      // 高胜率，适合激进的反马丁格尔
      increaseRatio = Math.min(3.0, 1.8 + (winProb - 0.5) * 3)
      decreaseRatio = Math.max(0.2, 0.6 - (winProb - 0.5) * 0.8)
      pyramidLevels = Math.min(8, Math.max(3, Math.floor((winProb - 0.4) * 10)))
    } else if (winProb > 0.5) {
      // 中高胜率
      increaseRatio = 1.6 + (winProb - 0.5) * 2
      decreaseRatio = 0.7 - (winProb - 0.5) * 0.4
      pyramidLevels = 5
    } else {
      // 相对较低胜率，温和反马丁格尔
      increaseRatio = 1.3 + kellyRatio * 0.5
      decreaseRatio = 0.8
      pyramidLevels = 3
    }
  }

  return {
    initialPosition: Math.round(initialPosition * 10000) / 10000,
    increaseRatio: Math.round(increaseRatio * 100) / 100,
    decreaseRatio: Math.round(decreaseRatio * 100) / 100,
    pyramidLevels: pyramidLevels,
  }
}

// getSuggestion 只保留与马丁格尔和反马丁格尔策略相关的建议，去除凯利公式分析部分
function getSuggestion(winProb: number, winOdds: number) {
  // 只保留马丁格尔与反马丁格尔策略参数推荐和应用说明
  const martingaleParams = calculateMartingaleOptimalParams(winProb, winOdds)
  const antiMartingaleParams = calculateAntiMartingaleOptimalParams(winProb, winOdds)
  martingaleOptimalParams.value = martingaleParams
  antiMartingaleOptimalParams.value = antiMartingaleParams
  let suggestion = `🔴 马丁格尔策略最优参数：\n`
  suggestion += `• 初始头寸比例：${(martingaleParams.initialPosition * 100).toFixed(2)}%\n`
  suggestion += `• 下注增长比例：${martingaleParams.increaseRatio}倍\n`
  suggestion += `• 下注降低比例：${(martingaleParams.decreaseRatio * 100).toFixed(0)}%\n`
  suggestion += `• 最大金字塔层数：${martingaleParams.pyramidLevels}层\n\n`
  suggestion += `🟢 反马丁格尔策略最优参数：\n`
  suggestion += `• 初始头寸比例：${(antiMartingaleParams.initialPosition * 100).toFixed(2)}%\n`
  suggestion += `• 下注增长比例：${antiMartingaleParams.increaseRatio}倍\n`
  suggestion += `• 下注降低比例：${(antiMartingaleParams.decreaseRatio * 100).toFixed(0)}%\n`
  suggestion += `• 最大金字塔层数：${antiMartingaleParams.pyramidLevels}层\n\n`
  suggestion += `可点击下方按钮一键应用对应策略参数。`
  showMartingaleApply.value = true
  showAntiMartingaleApply.value = true
  return suggestion
}

// 应用推荐参数
function applyRecommendedParams() {
  if (recommendedParams.value) {
    // 根据推荐策略设置参数
    if (recommendedParams.value.strategy === 'conservative') {
      betIncreaseRatio.value = 1.2
      betDecreaseRatio.value = 0.85
      maxPyramidLevels.value = 8
    } else if (recommendedParams.value.strategy === 'moderate') {
      betIncreaseRatio.value = 1.5
      betDecreaseRatio.value = 0.7
      maxPyramidLevels.value = 5
    } else if (recommendedParams.value.strategy === 'aggressive') {
      betIncreaseRatio.value = 2.0
      betDecreaseRatio.value = 0.5
      maxPyramidLevels.value = 3
    } else if (recommendedParams.value.strategy === 'optimal') {
      // 应用理论最优参数
      const optimalParams = calculateOptimalParams(winProb.value, winOdds.value)
      initialPositionRatio.value = optimalParams.initialPosition
      betIncreaseRatio.value = optimalParams.increaseRatio
      betDecreaseRatio.value = optimalParams.decreaseRatio
      maxPyramidLevels.value = optimalParams.pyramidLevels
    }
    showQuickApply.value = false
  }
}

// 应用马丁格尔策略最优参数
function applyMartingaleParams() {
  if (martingaleOptimalParams.value) {
    initialPositionRatio.value = martingaleOptimalParams.value.initialPosition
    betIncreaseRatio.value = martingaleOptimalParams.value.increaseRatio
    betDecreaseRatio.value = martingaleOptimalParams.value.decreaseRatio
    maxPyramidLevels.value = martingaleOptimalParams.value.pyramidLevels
    showMartingaleApply.value = false
    runSimulation() // 应用后自动运行模拟
  }
}

// 应用反马丁格尔策略最优参数
function applyAntiMartingaleParams() {
  if (antiMartingaleOptimalParams.value) {
    initialPositionRatio.value = antiMartingaleOptimalParams.value.initialPosition
    betIncreaseRatio.value = antiMartingaleOptimalParams.value.increaseRatio
    betDecreaseRatio.value = antiMartingaleOptimalParams.value.decreaseRatio
    maxPyramidLevels.value = antiMartingaleOptimalParams.value.pyramidLevels
    showAntiMartingaleApply.value = false
    runSimulation() // 应用后自动运行模拟
  }
}

async function runSimulation() {
  running.value = true
  result.value = ''
  suggestion.value = ''
  showQuickApply.value = false
  showMartingaleApply.value = false
  showAntiMartingaleApply.value = false
  recommendedParams.value = null
  martingaleOptimalParams.value = null
  antiMartingaleOptimalParams.value = null
  await new Promise((resolve) => setTimeout(resolve, 10)) // 让UI先刷新
  const params: SimulationParams = {
    initialCapital: initialCapital.value,
    initialPositionRatio: initialPositionRatio.value,
    coinFlipTimes: coinFlipTimes.value,
    threadCount: threadCount.value,
    winProb: winProb.value,
    winOdds: winOdds.value,
    maxPyramidLevels: maxPyramidLevels.value,
    betIncreaseRatio: betIncreaseRatio.value,
    betDecreaseRatio: betDecreaseRatio.value,
  }
  const martingaleResults: number[] = []
  const antiMartingaleResults: number[] = []
  let martingaleBusts = 0
  let antiMartingaleBusts = 0
  for (let i = 0; i < params.threadCount; i++) {
    const m = simulateMartingale(params)
    martingaleResults.push(m.capital)
    if (m.bust) martingaleBusts++
    const a = simulateAntiMartingale(params)
    antiMartingaleResults.push(a.capital)
    if (a.bust) antiMartingaleBusts++
  }
  // 统计
  const avg = (arr: number[]) => arr.reduce((a, b) => a + b, 0) / arr.length
  const min = (arr: number[]) => Math.min(...arr)
  const max = (arr: number[]) => Math.max(...arr)

  result.value =
    `胜率设置：${(params.winProb * 100).toFixed(1)}%\n` +
    `胜利赔率：${params.winOdds}倍\n` +
    `初始头寸比例：${(params.initialPositionRatio * 100).toFixed(1)}%\n` +
    `最大金字塔层数：${params.maxPyramidLevels}层\n` +
    `下注增长比例：${params.betIncreaseRatio.toFixed(2)}倍\n` +
    `下注降低比例：${(params.betDecreaseRatio * 100).toFixed(1)}%\n\n` +
    `马丁格尔策略：\n` +
    `平均最终资金: ${avg(martingaleResults).toFixed(2)}\n` +
    `最高最终资金: ${max(martingaleResults).toFixed(2)}\n` +
    `最低最终资金: ${min(martingaleResults).toFixed(2)}\n` +
    `爆仓次数: ${martingaleBusts} 次，爆仓率: ${((martingaleBusts / params.threadCount) * 100).toFixed(2)}%\n\n` +
    `反马丁格尔策略：\n` +
    `平均最终资金: ${avg(antiMartingaleResults).toFixed(2)}\n` +
    `最高最终资金: ${max(antiMartingaleResults).toFixed(2)}\n` +
    `最低最终资金: ${min(antiMartingaleResults).toFixed(2)}\n` +
    `爆仓次数: ${antiMartingaleBusts} 次，爆仓率: ${((antiMartingaleBusts / params.threadCount) * 100).toFixed(2)}%`
  suggestion.value = getSuggestion(params.winProb, params.winOdds)
  running.value = false
}
</script>

<template>
  <section class="simulator">
    <form @submit.prevent="runSimulation" class="sim-form">
      <h2 class="form-title">模拟参数设置</h2>

      <!-- 基础参数 -->
      <div class="param-group">
        <h3 class="group-title">基础参数</h3>
        <div class="form-grid">
          <div class="form-field">
            <label>初始资金</label>
            <input type="number" v-model.number="initialCapital" min="1" step="1" />
          </div>
          <div class="form-field">
            <label>每线程游戏次数</label>
            <input type="number" v-model.number="coinFlipTimes" min="1" step="1" />
          </div>
          <div class="form-field">
            <label>线程数量</label>
            <input type="number" v-model.number="threadCount" min="1" step="1" />
          </div>
        </div>
      </div>

      <!-- 概率参数 -->
      <div class="param-group">
        <h3 class="group-title">概率参数</h3>
        <div class="form-grid">
          <div class="form-field">
            <label>胜率</label>
            <input type="number" v-model.number="winProb" min="0" max="1" step="0.01" />
          </div>
          <div class="form-field">
            <label>赔率</label>
            <input type="number" v-model.number="winOdds" min="1" step="0.01" />
          </div>
        </div>
      </div>

      <!-- 策略参数 -->
      <div class="param-group">
        <h3 class="group-title">策略参数</h3>
        <div class="form-grid">
          <div class="form-field">
            <label>初始头寸比例 (%)</label>
            <input
              type="number"
              v-model.number="initialPositionRatio"
              min="0.0001"
              max="1"
              step="0.0001"
              title="初始下注占总资金的百分比"
            />
          </div>
          <div class="form-field">
            <label>最大金字塔层数</label>
            <input
              type="number"
              v-model.number="maxPyramidLevels"
              min="0"
              max="20"
              step="1"
              title="限制连续调整的最大次数，0表示固定下注不调整"
            />
          </div>
          <div class="form-field">
            <label>下注增长比例</label>
            <input
              type="number"
              v-model.number="betIncreaseRatio"
              min="1.01"
              max="5"
              step="0.01"
              title="失败后下注增长的倍数"
            />
          </div>
          <div class="form-field">
            <label>下注降低比例</label>
            <input
              type="number"
              v-model.number="betDecreaseRatio"
              min="0.1"
              max="0.99"
              step="0.01"
              title="成功后下注保留的比例"
            />
          </div>
        </div>
      </div>

      <div class="submit-section">
        <button type="submit" :disabled="running" class="run-button">
          <span v-if="running" class="loading-spinner"></span>
          {{ running ? '运行中...' : '开始模拟' }}
        </button>
      </div>
    </form>

    <div v-if="result" class="result-block">
      <h2 class="result-title">模拟结果</h2>
      <div class="result-content">
        <pre class="result-text">{{ result }}</pre>
        <div class="suggestion-block">
          <h3>💡 智能参数建议</h3>
          <div class="suggestion-content">{{ suggestion }}</div>
          <div class="quick-apply-section">
            <div v-if="showMartingaleApply && martingaleOptimalParams" class="quick-apply">
              <button @click="applyMartingaleParams" class="apply-button martingale-button">
                🔴 应用马丁格尔最优参数
              </button>
            </div>
            <div v-if="showAntiMartingaleApply && antiMartingaleOptimalParams" class="quick-apply">
              <button @click="applyAntiMartingaleParams" class="apply-button anti-martingale-button">
                🟢 应用反马丁格尔最优参数
              </button>
            </div>
            <div v-if="showQuickApply && recommendedParams" class="quick-apply">
              <button @click="applyRecommendedParams" class="apply-button general-button">
                🎯 应用通用理论最优参数
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>

<style scoped>
.simulator {
  max-width: 95%;
  margin: 0 auto;
  width: 100%;
  padding: 1rem 1rem 0 1rem;
}

.sim-form {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  margin-bottom: 2rem;
}

.form-title {
  font-size: 1.5rem;
  color: #2c3e50;
  margin: 0 0 1.5rem 0;
  text-align: center;
  font-weight: 600;
}

.param-group {
  margin-bottom: 2rem;
}

.group-title {
  font-size: 1.1rem;
  color: #34495e;
  margin: 0 0 1rem 0;
  font-weight: 500;
  border-bottom: 2px solid #ecf0f1;
  padding-bottom: 0.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.2rem;
}

.form-field {
  display: flex;
  flex-direction: column;
}

.form-field label {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 0.3rem;
  font-weight: 500;
}

.form-field input[type='number'] {
  padding: 0.6rem;
  border: 2px solid #e0e6ed;
  border-radius: 6px;
  font-size: 1rem;
  transition: all 0.3s ease;
  background: #f8f9fa;
}

.form-field input[type='number']:focus {
  outline: none;
  border-color: #667eea;
  background: white;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.submit-section {
  text-align: center;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #ecf0f1;
}

.run-button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 0.8rem 2.5rem;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  min-width: 140px;
}

.run-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

.run-button:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 0.5rem;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.result-block {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.result-title {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  margin: 0;
  padding: 1rem 1.5rem;
  font-size: 1.3rem;
  font-weight: 600;
}

.result-content {
  padding: 1.5rem;
}

.result-text {
  background: #f8f9fa;
  padding: 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.6;
  margin: 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.suggestion-block {
  margin-top: 1.5rem;
  padding: 1rem;
  background: linear-gradient(135deg, #e8f5e8 0%, #f0f8ff 100%);
  border-radius: 8px;
  border-left: 4px solid #27ae60;
}

.suggestion-block h3 {
  margin: 0 0 0.5rem 0;
  color: #27ae60;
  font-size: 1rem;
}

.suggestion-content {
  margin: 0;
  color: #2c3e50;
  line-height: 1.6;
  white-space: pre-line;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.quick-apply {
  margin-top: 1rem;
  text-align: center;
}

.quick-apply-section {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 1rem;
}

.apply-button {
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 100%;
}

.martingale-button {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  color: white;
}

.martingale-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.anti-martingale-button {
  background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
  color: white;
}

.anti-martingale-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
}

.general-button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.general-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

/* 手机端 - 768px以下 */
@media (max-width: 768px) {
  .simulator {
    padding: 1rem 0.5rem 0 0.5rem;
  }

  .sim-form {
    padding: 1rem;
    margin: 0 0 1rem 0;
  }

  .form-title {
    font-size: 1.3rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 0.8rem;
  }

  .param-group {
    margin-bottom: 1.5rem;
  }

  .run-button {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
  }

  .result-content {
    padding: 1rem;
  }

  .result-text {
    font-size: 0.85rem;
    padding: 0.8rem;
  }

  .suggestion-block {
    padding: 0.8rem;
  }

  .quick-apply-section {
    gap: 0.6rem;
  }

  .apply-button {
    padding: 0.8rem 1rem;
    font-size: 0.85rem;
  }
}

/* 平板端 - 769px-1024px */
@media (min-width: 769px) and (max-width: 1024px) {
  .simulator {
    max-width: 95%;
    padding: 1rem 1rem 0 1rem;
  }

  .sim-form {
    padding: 1.5rem;
  }

  .form-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.2rem;
  }

  .quick-apply-section {
    flex-direction: row;
    gap: 1rem;
  }

  .apply-button {
    width: auto;
    min-width: 150px;
  }
}

/* 桌面端 - 1025px以上 */
@media (min-width: 1025px) {
  .simulator {
    max-width: 90%;
    padding: 1rem 2rem 0 2rem;
  }

  .sim-form {
    padding: 2rem;
  }

  .form-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
  }

  .result-content {
    padding: 2rem;
  }

  .result-text {
    font-size: 1rem;
    padding: 1.5rem;
  }

  .quick-apply-section {
    flex-direction: row;
    justify-content: center;
    gap: 1rem;
  }

  .apply-button {
    width: auto;
    min-width: 200px;
  }
}
</style>
